package jp.co.neosystem.adwg.neodiary.db;

import jp.co.neosystem.adwg.neodiary.db.entity.Diary;
import jp.co.neosystem.adwg.neodiary.util.Constants;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * @author NEOSystem
 */
public class DBOpenHelper extends SQLiteOpenHelper
{
	/**
	 * コンストラクタ
	 * 
	 * @param context
	 * @param name
	 * @param factory
	 * @param version
	 */
	public DBOpenHelper(Context context, String name, CursorFactory factory, int version)
	{
		super(context, Constants.DATABASE_NAME.getValue(), factory, version);
	}

	/**
	 * onCreateメソッド
	 * 
	 * @param db
	 */
	@Override
	public void onCreate(SQLiteDatabase db)
	{
		db.beginTransaction();
		
		try
		{
			// テーブル作成
			db.execSQL(new Diary().getCreateTableSql());
			
			db.setTransactionSuccessful();
		}
		finally
		{
			db.endTransaction();
		}
	}

	/**
	 * onUpgradeメソッド
	 * 
	 * @param db
	 * @param oldVersion
	 * @param newVersion
	 */
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
		// NOP
	}
}
